package b.l.a;

import android.view.animation.Interpolator;
import androidx.fragment.app.Fragment;
import b.l.a.i.h;
import b.n.d.b;
import com.huawei.hms.analytics.core.crypto.AesCipher.AesLen;
import java.io.PrintWriter;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Objects;

/* compiled from: BackStackRecord */
public final class a extends p implements h {
    public final i q;
    public boolean r;
    public int s = -1;

    public a(i iVar) {
        this.q = iVar;
    }

    public static boolean r(b.l.a.p.a aVar) {
        Fragment fragment = aVar.b;
        if (!(fragment == null || !fragment.k || fragment.G == null || fragment.z || fragment.y)) {
            androidx.fragment.app.Fragment.a aVar2 = fragment.K;
        }
        return false;
    }

    public boolean a(ArrayList<a> arrayList, ArrayList<Boolean> arrayList2) {
        Interpolator interpolator = i.G;
        arrayList.add(this);
        arrayList2.add(Boolean.FALSE);
        if (this.h) {
            i iVar = this.q;
            if (iVar.h == null) {
                iVar.h = new ArrayList();
            }
            iVar.h.add(this);
        }
        return true;
    }

    public void d() {
        if (this.h) {
            throw new IllegalStateException("This transaction is already being added to the back stack");
        }
        i iVar = this.q;
        if (iVar.p != null && !iVar.w) {
            iVar.T(true);
            a(iVar.y, iVar.z);
            iVar.d = true;
            try {
                iVar.m0(iVar.y, iVar.z);
                iVar.x0();
                iVar.Q();
                iVar.k();
            } finally {
                iVar.m();
            }
        }
    }

    public p e(Fragment fragment) {
        i iVar = fragment.r;
        if (iVar == null || iVar == this.q) {
            b(new b.l.a.p.a(6, fragment));
            return this;
        }
        StringBuilder g = c.b.a.a.a.g("Cannot detach Fragment attached to a different FragmentManager. Fragment ");
        g.append(fragment.toString());
        g.append(" is already attached to a FragmentManager.");
        throw new IllegalStateException(g.toString());
    }

    public void f(int i, Fragment fragment, String str, int i2) {
        Class cls = fragment.getClass();
        int modifiers = cls.getModifiers();
        if (cls.isAnonymousClass() || !Modifier.isPublic(modifiers) || (cls.isMemberClass() && !Modifier.isStatic(modifiers))) {
            StringBuilder g = c.b.a.a.a.g("Fragment ");
            g.append(cls.getCanonicalName());
            g.append(" must be a public static class to be  properly recreated from instance state.");
            throw new IllegalStateException(g.toString());
        }
        StringBuilder stringBuilder;
        String str2 = " now ";
        String str3 = ": was ";
        if (str != null) {
            String str4 = fragment.x;
            if (str4 == null || str.equals(str4)) {
                fragment.x = str;
            } else {
                stringBuilder = new StringBuilder();
                stringBuilder.append("Can't change tag of fragment ");
                stringBuilder.append(fragment);
                stringBuilder.append(str3);
                throw new IllegalStateException(c.b.a.a.a.e(stringBuilder, fragment.x, str2, str));
            }
        }
        if (i != 0) {
            if (i != -1) {
                int i3 = fragment.v;
                if (i3 == 0 || i3 == i) {
                    fragment.v = i;
                    fragment.w = i;
                } else {
                    stringBuilder = new StringBuilder();
                    stringBuilder.append("Can't change container ID of fragment ");
                    stringBuilder.append(fragment);
                    stringBuilder.append(str3);
                    stringBuilder.append(fragment.v);
                    stringBuilder.append(str2);
                    stringBuilder.append(i);
                    throw new IllegalStateException(stringBuilder.toString());
                }
            }
            stringBuilder = new StringBuilder();
            stringBuilder.append("Can't add fragment ");
            stringBuilder.append(fragment);
            stringBuilder.append(" with tag ");
            stringBuilder.append(str);
            stringBuilder.append(" to container view with no id");
            throw new IllegalArgumentException(stringBuilder.toString());
        }
        b(new b.l.a.p.a(i2, fragment));
        fragment.r = this.q;
    }

    public p g(Fragment fragment) {
        i iVar = fragment.r;
        if (iVar == null || iVar == this.q) {
            b(new b.l.a.p.a(3, fragment));
            return this;
        }
        StringBuilder g = c.b.a.a.a.g("Cannot remove Fragment attached to a different FragmentManager. Fragment ");
        g.append(fragment.toString());
        g.append(" is already attached to a FragmentManager.");
        throw new IllegalStateException(g.toString());
    }

    public p h(Fragment fragment, b bVar) {
        StringBuilder stringBuilder;
        if (fragment.r == this.q) {
            b bVar2 = b.CREATED;
            if ((bVar.compareTo(bVar2) >= 0 ? 1 : null) != null) {
                b(new b.l.a.p.a(10, fragment, bVar));
                return this;
            }
            stringBuilder = new StringBuilder();
            stringBuilder.append("Cannot set maximum Lifecycle below ");
            stringBuilder.append(bVar2);
            throw new IllegalArgumentException(stringBuilder.toString());
        }
        stringBuilder = c.b.a.a.a.g("Cannot setMaxLifecycle for Fragment not attached to FragmentManager ");
        stringBuilder.append(this.q);
        throw new IllegalArgumentException(stringBuilder.toString());
    }

    public void i(int i) {
        if (this.h) {
            Interpolator interpolator = i.G;
            int size = this.a.size();
            for (int i2 = 0; i2 < size; i2++) {
                Fragment fragment = ((b.l.a.p.a) this.a.get(i2)).b;
                if (fragment != null) {
                    fragment.q += i;
                    Interpolator interpolator2 = i.G;
                }
            }
        }
    }

    public int j() {
        return l(false);
    }

    public int k() {
        return l(true);
    }

    public int l(boolean z) {
        if (this.r) {
            throw new IllegalStateException("commit already called");
        }
        Interpolator interpolator = i.G;
        this.r = true;
        if (this.h) {
            int intValue;
            i iVar = this.q;
            synchronized (iVar) {
                ArrayList arrayList = iVar.m;
                if (arrayList != null) {
                    if (arrayList.size() > 0) {
                        arrayList = iVar.m;
                        intValue = ((Integer) arrayList.remove(arrayList.size() - 1)).intValue();
                        iVar.l.set(intValue, this);
                    }
                }
                if (iVar.l == null) {
                    iVar.l = new ArrayList();
                }
                intValue = iVar.l.size();
                iVar.l.add(this);
            }
            this.s = intValue;
        } else {
            this.s = -1;
        }
        this.q.S(this, z);
        return this.s;
    }

    public void m(String str, PrintWriter printWriter, boolean z) {
        if (z) {
            printWriter.print(str);
            printWriter.print("mName=");
            printWriter.print(this.i);
            printWriter.print(" mIndex=");
            printWriter.print(this.s);
            printWriter.print(" mCommitted=");
            printWriter.println(this.r);
            if (this.f != 0) {
                printWriter.print(str);
                printWriter.print("mTransition=#");
                printWriter.print(Integer.toHexString(this.f));
                printWriter.print(" mTransitionStyle=#");
                printWriter.println(Integer.toHexString(this.g));
            }
            if (!(this.b == 0 && this.c == 0)) {
                printWriter.print(str);
                printWriter.print("mEnterAnim=#");
                printWriter.print(Integer.toHexString(this.b));
                printWriter.print(" mExitAnim=#");
                printWriter.println(Integer.toHexString(this.c));
            }
            if (!(this.d == 0 && this.e == 0)) {
                printWriter.print(str);
                printWriter.print("mPopEnterAnim=#");
                printWriter.print(Integer.toHexString(this.d));
                printWriter.print(" mPopExitAnim=#");
                printWriter.println(Integer.toHexString(this.e));
            }
            if (!(this.j == 0 && this.k == null)) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbTitleRes=#");
                printWriter.print(Integer.toHexString(this.j));
                printWriter.print(" mBreadCrumbTitleText=");
                printWriter.println(this.k);
            }
            if (!(this.l == 0 && this.m == null)) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbShortTitleRes=#");
                printWriter.print(Integer.toHexString(this.l));
                printWriter.print(" mBreadCrumbShortTitleText=");
                printWriter.println(this.m);
            }
        }
        if (!this.a.isEmpty()) {
            printWriter.print(str);
            printWriter.println("Operations:");
            int size = this.a.size();
            for (int i = 0; i < size; i++) {
                String str2;
                b.l.a.p.a aVar = (b.l.a.p.a) this.a.get(i);
                switch (aVar.a) {
                    case 0:
                        str2 = "NULL";
                        break;
                    case 1:
                        str2 = "ADD";
                        break;
                    case 2:
                        str2 = "REPLACE";
                        break;
                    case 3:
                        str2 = "REMOVE";
                        break;
                    case 4:
                        str2 = "HIDE";
                        break;
                    case 5:
                        str2 = "SHOW";
                        break;
                    case 6:
                        str2 = "DETACH";
                        break;
                    case 7:
                        str2 = "ATTACH";
                        break;
                    case 8:
                        str2 = "SET_PRIMARY_NAV";
                        break;
                    case 9:
                        str2 = "UNSET_PRIMARY_NAV";
                        break;
                    case 10:
                        str2 = "OP_SET_MAX_LIFECYCLE";
                        break;
                    default:
                        StringBuilder g = c.b.a.a.a.g("cmd=");
                        g.append(aVar.a);
                        str2 = g.toString();
                        break;
                }
                printWriter.print(str);
                printWriter.print("  Op #");
                printWriter.print(i);
                printWriter.print(": ");
                printWriter.print(str2);
                printWriter.print(" ");
                printWriter.println(aVar.b);
                if (z) {
                    if (!(aVar.c == 0 && aVar.d == 0)) {
                        printWriter.print(str);
                        printWriter.print("enterAnim=#");
                        printWriter.print(Integer.toHexString(aVar.c));
                        printWriter.print(" exitAnim=#");
                        printWriter.println(Integer.toHexString(aVar.d));
                    }
                    if (aVar.e != 0 || aVar.f != 0) {
                        printWriter.print(str);
                        printWriter.print("popEnterAnim=#");
                        printWriter.print(Integer.toHexString(aVar.e));
                        printWriter.print(" popExitAnim=#");
                        printWriter.println(Integer.toHexString(aVar.f));
                    }
                }
            }
        }
    }

    public void n() {
        int size = this.a.size();
        for (int i = 0; i < size; i++) {
            b.l.a.p.a aVar = (b.l.a.p.a) this.a.get(i);
            Fragment fragment = aVar.b;
            if (fragment != null) {
                int i2 = this.f;
                int i3 = this.g;
                if (!(fragment.K == null && i2 == 0 && i3 == 0)) {
                    fragment.b();
                    androidx.fragment.app.Fragment.a aVar2 = fragment.K;
                    aVar2.e = i2;
                    aVar2.f = i3;
                }
            }
            switch (aVar.a) {
                case 1:
                    fragment.h0(aVar.c);
                    this.q.h(fragment, false);
                    break;
                case 3:
                    fragment.h0(aVar.d);
                    this.q.l0(fragment);
                    break;
                case 4:
                    fragment.h0(aVar.d);
                    Objects.requireNonNull(this.q);
                    if (!fragment.y) {
                        fragment.y = true;
                        fragment.M ^= 1;
                        break;
                    }
                    break;
                case 5:
                    fragment.h0(aVar.c);
                    Objects.requireNonNull(this.q);
                    if (fragment.y) {
                        fragment.y = false;
                        fragment.M ^= 1;
                        break;
                    }
                    break;
                case 6:
                    fragment.h0(aVar.d);
                    this.q.o(fragment);
                    break;
                case 7:
                    fragment.h0(aVar.c);
                    this.q.j(fragment);
                    break;
                case 8:
                    this.q.u0(fragment);
                    break;
                case 9:
                    this.q.u0(null);
                    break;
                case 10:
                    this.q.t0(fragment, aVar.h);
                    break;
                default:
                    StringBuilder g = c.b.a.a.a.g("Unknown cmd: ");
                    g.append(aVar.a);
                    throw new IllegalArgumentException(g.toString());
            }
            if (!(this.p || aVar.a == 1 || fragment == null)) {
                this.q.f0(fragment);
            }
        }
        if (!this.p) {
            i iVar = this.q;
            iVar.g0(iVar.o, true);
        }
    }

    public void o(boolean z) {
        for (int size = this.a.size() - 1; size >= 0; size--) {
            b.l.a.p.a aVar = (b.l.a.p.a) this.a.get(size);
            Fragment fragment = aVar.b;
            if (fragment != null) {
                int i = this.f;
                Interpolator interpolator = i.G;
                int i2 = 8194;
                if (i != 4097) {
                    i2 = i != 4099 ? i != 8194 ? 0 : 4097 : 4099;
                }
                i = this.g;
                if (!(fragment.K == null && i2 == 0 && i == 0)) {
                    fragment.b();
                    androidx.fragment.app.Fragment.a aVar2 = fragment.K;
                    aVar2.e = i2;
                    aVar2.f = i;
                }
            }
            switch (aVar.a) {
                case 1:
                    fragment.h0(aVar.f);
                    this.q.l0(fragment);
                    break;
                case 3:
                    fragment.h0(aVar.e);
                    this.q.h(fragment, false);
                    break;
                case 4:
                    fragment.h0(aVar.e);
                    Objects.requireNonNull(this.q);
                    if (fragment.y) {
                        fragment.y = false;
                        fragment.M ^= 1;
                        break;
                    }
                    break;
                case 5:
                    fragment.h0(aVar.f);
                    Objects.requireNonNull(this.q);
                    if (!fragment.y) {
                        fragment.y = true;
                        fragment.M ^= 1;
                        break;
                    }
                    break;
                case 6:
                    fragment.h0(aVar.e);
                    this.q.j(fragment);
                    break;
                case 7:
                    fragment.h0(aVar.f);
                    this.q.o(fragment);
                    break;
                case 8:
                    this.q.u0(null);
                    break;
                case 9:
                    this.q.u0(fragment);
                    break;
                case 10:
                    this.q.t0(fragment, aVar.g);
                    break;
                default:
                    StringBuilder g = c.b.a.a.a.g("Unknown cmd: ");
                    g.append(aVar.a);
                    throw new IllegalArgumentException(g.toString());
            }
            if (!(this.p || aVar.a == 3 || fragment == null)) {
                this.q.f0(fragment);
            }
        }
        if (!this.p && z) {
            i iVar = this.q;
            iVar.g0(iVar.o, true);
        }
    }

    public boolean p(int i) {
        int size = this.a.size();
        for (int i2 = 0; i2 < size; i2++) {
            Fragment fragment = ((b.l.a.p.a) this.a.get(i2)).b;
            int i3 = fragment != null ? fragment.w : 0;
            if (i3 != 0 && i3 == i) {
                return true;
            }
        }
        return false;
    }

    public boolean q(ArrayList<a> arrayList, int i, int i2) {
        if (i2 == i) {
            return false;
        }
        int size = this.a.size();
        int i3 = -1;
        for (int i4 = 0; i4 < size; i4++) {
            Fragment fragment = ((b.l.a.p.a) this.a.get(i4)).b;
            int i5 = fragment != null ? fragment.w : 0;
            if (!(i5 == 0 || i5 == i3)) {
                for (i3 = i; i3 < i2; i3++) {
                    a aVar = (a) arrayList.get(i3);
                    int size2 = aVar.a.size();
                    for (int i6 = 0; i6 < size2; i6++) {
                        Fragment fragment2 = ((b.l.a.p.a) aVar.a.get(i6)).b;
                        if ((fragment2 != null ? fragment2.w : 0) == i5) {
                            return true;
                        }
                    }
                }
                i3 = i5;
            }
        }
        return false;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder(AesLen.ROOTKEY_COMPONET_LEN);
        stringBuilder.append("BackStackEntry{");
        stringBuilder.append(Integer.toHexString(System.identityHashCode(this)));
        if (this.s >= 0) {
            stringBuilder.append(" #");
            stringBuilder.append(this.s);
        }
        if (this.i != null) {
            stringBuilder.append(" ");
            stringBuilder.append(this.i);
        }
        stringBuilder.append("}");
        return stringBuilder.toString();
    }
}
